package estore;

public class Product implements Comparable<Product> {
    private String id;
    private String name;
    private double price;
    private int stock;

    public Product(String id, String name, double price, int stock) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
    }

    // getter 方法
    public String getId() { return id; }
    public String getName() { return name; }
    public double getPrice() { return price; }
    public int getStock() { return stock; }

    @Override
    public int compareTo(Product other) {
        return this.id.compareTo(other.id);
    }

    @Override
    public String toString() {
        return String.format("商品ID: %s | 名称: %-15s | 价格: ¥%-8.2f | 库存: %d",
                id, name, price, stock);
    }
}

